import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-04-01
 * Time: 15:38
 */
public class Demo3 {

    public static void main1(String[] args) throws InterruptedException {
        Map<Integer, Integer> map1 = new HashMap<>();
        Map<Integer, Integer> map2 = new Hashtable<>();
        Map<Integer, Integer> map3 = new ConcurrentHashMap<>();

        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 1000000; i++) {
                map1.put(i % 1000, i);
                map2.put(i % 1000, i);
                map3.put(i % 1000, i);
            }
        });
        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 1000000; i++) {
                map1.put(i % 1000, i);
                map2.put(i % 1000, i);
                map3.put(i % 1000, i);
            }
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println(map1.size());
        System.out.println(map2.size());
        System.out.println(map3.size());
        System.out.println(map1);
        System.out.println(map2);
        System.out.println(map3);//ConcurrentHashMap和HashTable打印方法不同，刚好相反~
    }

}
